"""
演示reduceByKey算子的使用
"""

from pyspark import SparkContext,SparkConf
import os

os.environ['PYSPARK_PYTHON'] = "C:/Users/86131/AppData/Local/Programs/Python/Python39/python.exe"
conf = SparkConf().setMaster("local[*]").setAppName("test_spark")
sc = SparkContext(conf=conf)

#构建一个RDD
rdd = sc.parallelize([('男',99),('女',89),('男',79),('女',69)])

#求男生和女生的成绩之和

rdd2 = rdd.reduceByKey(lambda a,b: a+b)

print(rdd2.collect())



